import bisect

def get_num(l):
    result_list = []
    for i in l:
        pos = bisect.bisect_left(result_list, i)
        if pos == len(result_list):
            result_list.append(i)
        else:
            result_list[pos] = i
    return len(result_list)


while True:
    n = int(input())
    if n:
        line = [int(v) for v in input().split(' ')]
        print(get_num(line))
    else:
        break
